<?php

/**
 * This is the model class for table "m_tahun_ajaran".
 *
 * The followings are the available columns in table 'm_tahun_ajaran':
 * @property integer $id
 * @property integer $pos
 * @property string $department_id
 * @property string $name
 * @property string $start_date
 * @property string $end_date
 * @property string $description
 * @property string $sid_prefix
 * @property integer $is_active
 *
 * The followings are the available model relations:
 * @property MJadwalPelajaran[] $mJadwalPelajarans
 * @property MKalenderAkademik[] $mKalenderAkademiks
 * @property MKelasTahunAjaran[] $mKelasTahunAjarans
 * @property MPenilaian[] $mPenilaians
 * @property MStudent[] $mStudents
 * @property MDepartment $department
 */
class MTahunAjaran extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_tahun_ajaran';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pos, department_id, name, start_date, end_date, sid_prefix', 'required'),
			array('pos, is_active', 'numerical', 'integerOnly'=>true),
			array('department_id', 'length', 'max'=>20),
			array('name', 'length', 'max'=>100),
			array('description', 'length', 'max'=>255),
			array('sid_prefix', 'length', 'max'=>10),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, pos, department_id, name, start_date, end_date, description, sid_prefix, is_active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'mJadwalPelajarans' => array(self::HAS_MANY, 'MJadwalPelajaran', 'tahun_ajaran_id'),
			'mKalenderAkademiks' => array(self::HAS_MANY, 'MKalenderAkademik', 'tahun_ajaran_id'),
			'mKelasTahunAjarans' => array(self::HAS_MANY, 'MKelasTahunAjaran', 'tahun_ajaran_id'),
			'mPenilaians' => array(self::HAS_MANY, 'MPenilaian', 'tahun_ajaran_id'),
			'mStudents' => array(self::HAS_MANY, 'MStudent', 'tahun_ajaran_id'),
			'department' => array(self::BELONGS_TO, 'MDepartment', 'department_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'pos' => 'Pos',
			'department_id' => 'Department',
			'name' => 'Name',
			'start_date' => 'Start Date',
			'end_date' => 'End Date',
			'description' => 'Description',
			'sid_prefix' => 'Sid Prefix',
			'is_active' => 'Is Active',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('pos',$this->pos);
		$criteria->compare('department_id',$this->department_id,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('start_date',$this->start_date,true);
		$criteria->compare('end_date',$this->end_date,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('sid_prefix',$this->sid_prefix,true);
		$criteria->compare('is_active',$this->is_active);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MTahunAjaran the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
